package com.changan.stumgr.service;

import com.changan.stumgr.mapper.StudentMapper;
import com.changan.stumgr.pojo.Student;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public PageInfo<Student> selAllStudent(Integer pagaNum, Integer pageSize,String searchName) {
        if(null==searchName){//是null 给空值
            searchName="";
        }
        if(pagaNum==null || pagaNum<=0 ){
            pagaNum=1;
        }
        if (pageSize==null || pageSize<0 ){
            pageSize=4;
        }
        PageHelper.startPage(pagaNum, 3);
        List<Student> postIn = studentMapper.selAllStudent(searchName);
        System.out.println(postIn+"===========");
        PageInfo<Student> page = new PageInfo<Student>(postIn);

        return page;
    }

    @Override
    public int addStudent(Student student) {
        return studentMapper.addStudent(student);
    }

    @Override
    public int delStudent(Integer id) {
        return studentMapper.delStudent(id);
    }

    @Override
    public int updateStudent(Student student) {
        return studentMapper.updateStudent(student);
    }

    @Override
    public Student findStudentById(Integer id) {
        return studentMapper.findStudentById(id);
    }

    @Override
    public Student findByIdStudent(Integer id) {
        return studentMapper.findStudentById(id);
    }

}
